package common.db;

import member.initial.Login;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

public class TomSquareDBMethod {

	TomSquareDBHelper mHelper;
	Context context;
		
	public TomSquareDBMethod(Context context)
	{
		this.context = context;
		mHelper = new TomSquareDBHelper(context); 
	}
	
	public void insert(String query)
	{
		SQLiteDatabase db = mHelper.getWritableDatabase();
		db.execSQL(query+";");
		// insert query 예 : INSERT INTO dic VALUES (null, 'girl', '가시나')
		mHelper.close();
		Toast.makeText(context, "Insert Success!", 0).show();
	}
	
	public void deleteTable(String tableName)
	{
		SQLiteDatabase db = mHelper.getWritableDatabase();
		db.execSQL("DELETE FROM "+tableName+";");
		mHelper.close();
		Toast.makeText(context, "Delete Success!", 0).show();
	}
	
	public void update(String query)
	{
		SQLiteDatabase db = mHelper.getWritableDatabase();
		db.execSQL(query+";");
		//query 예 : UPDATE member SET pass = '**' WHERE email = '**'
		mHelper.close();
		Toast.makeText(context, "Update Success!", 0).show();
	}
	
	public Cursor select(String query)
	{
		SQLiteDatabase db = mHelper.getReadableDatabase();
				
		Cursor cursor = db.rawQuery(query, null);
		
		//cursor.close();
		mHelper.close();
		Toast.makeText(context, "Select Success!", 0).show();
		
		return cursor;
		
//		값 추출 예 : 안드로이드 1054page 참조
//		cursor = db.rawQuery("SELECT eng, han FROM dic", null);
//		String Result = "";
//		while (cursor.moveToNext()) {
//			String eng = cursor.getString(0);
//			String han = cursor.getString(1);
//			Result += (eng + " = " + han + "\n");
//		}
//
//		if (Result.length() == 0) {
//			mText.setText("Empyt Set");
//		} else {
//			mText.setText(Result);
//		}
	}
}
